<template>
    <div>
<table class="table table-bordered">
<tr>
    <td>优惠券类型</td>
    <td>
        <select v-model="info.disType">
            <option value="代金券">代金券</option>
            <option value="折扣券">折扣券</option>
            <option value="兑换券">兑换券</option>
        </select>
    </td>
</tr>

<tr>
    <td>标题</td>
    <td>
        <input type="text"  v-model="info.disTitle">
    </td>
</tr>
<tr>
    <td>副标题</td>
    <td>
        <input type="text"  v-model="info.fuDisTitle">
    </td>
</tr>
<tr>
    <td>剩余库存</td>
    <td>
        <input type="number"  v-model="info.kuCunNum">
    </td>
</tr>
<tr>
    <td>每人限额</td>
    <td>
        <input type="text"  v-model="info.xianLing">
    </td>
</tr>
<tr>
    <td>使用条件</td>
    <td>
        <input type="text"  v-model="info.tiaoJianNum">
    </td>
</tr>
<tr>
    <td>减免金额</td>
    <td>
        <input type="text"  v-model="info.price">
    </td>
</tr>
<tr>
    <td>有效期</td>
    <td>
        <input type="date"  v-model="info.createTime"> 
   --
        <input type="date"  v-model="info.endsTime">
    </td>
</tr>
<tr>
    <td>适用业务</td>
    <td>
    <input type="checkbox" :value="订房"   v-model="info.yeWu">订房
    <input type="checkbox" :value="商城"  v-model="info.yeWu">商城
    <input type="checkbox" :value="堂食"  v-model="info.yeWu">堂食
    <input type="checkbox" :value="收款码"  v-model="info.yeWu">收款码
    </td>
</tr>
<tr>
    <td>使用须知</td>
    <td>
        <textarea cols="50" rows="10"  v-model="info.desc">

        </textarea>
    </td>
</tr>
<tr>
    <td>图片</td>
    <td>
        <img :src="info.photo" alt="" height="80px" width="80px">
    </td>
</tr>
<tr>
    <td>使用门店</td>
    <td>
        <select v-model="info.dropId">
            <option value=""></option>
            <option v-for="item in drop" :value="item.id" :key="item.id">{{ item.dropName}}</option>
        </select>
    </td>
</tr>
<tr>
    <td>服务电话</td>
    <td>
        <input type="text"  v-model="info.phone">
    </td>
</tr>
<tr>
    <td></td>
    <td>
        <input type="button" class="btn btn-success" value="修改" @click="upd">
    </td>
</tr>
</table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref,reactive,onMounted } from 'vue';
import moment from 'moment';
import { useRoute,useRouter } from 'vue-router';
let router=useRouter();
let route=useRoute();
let drop:any=reactive({});//门店列表

let info:any=reactive({
    "id": route.query.id,
  "disType": "",
  "disTitle": "",
  "fuDisTitle": "",
  "photo": "https://localhost:7074/pic/1.jpg",
  "kuCunNum": 1,
  "xianLing": 1,
  "tiaoJianNum": 1,
  "createTime": "",
  "endsTime": "",
  "yeWu": [],
  "desc": "",
  "dropId": 1,
  "phone": "",
  "price": 1
});

/////////////////////////////////函数/////////////////////////////////

onMounted(()=>{
    fan();
    dropshow();
})

const dropshow=()=>{
    axios({
        url:'https://localhost:7074/api/Dis/GetDrop',
        method:'get'
    })
    .then(res=>{
        console.log(res);        
        drop=res.data
    })
}

const fan=()=>{
    axios({
        url:'https://localhost:7074/api/Dis/FanTianDis',
        params:{id:route.query.id},
        method:'get'
    })
    .then(res=>{
info.disType=res.data.disType;
info.disTitle=res.data.disTitle;
info.fuDisTitle=res.data.fuDisTitle;
info.photo=res.data.photo;
info.kuCunNum=res.data.kuCunNum;
info.xianLing=res.data.xianLing;
info.tiaoJianNum=res.data.tiaoJianNum;
info.createTime=res.data.createTime.substring(0,10);
info.endsTime=res.data.endsTime.substring(0,10);
info.yeWu=res.data.yeWu.aplit(',');
info.desc=res.data.desc;
info.dropId=res.data.dropId;
info.phone=res.data.phone;
info.price=res.data.price;
    })
}
//上传马云

const upd=()=>{
if(info.disType==''){
alert('类型不能为空');
return;
}
if(info.disTitle==''){
alert('类标题不能为空');
return;
}

if(info.photo==''){
alert('图片不能为空');
return;
}

if(info.kuCunNum==''){
alert('库存不能为空');
return;
}

if(info.desc==''){
alert('详情不能为空');
return;
}

if(info.phone==''){
alert('手机号不能为空');
return;
}


if(info.price==''){
alert('优惠金额不能为空');
return;
}


    axios({
        url:'https://localhost:7074/api/Dis/UpDis',
        data:info,
        method:'put'
    })
    .then(res=>{
        if(res.data>0){
alert('修改成功');
        }else{
            alert('修改失败')
        }
    })
}

</script>

<style scoped>

</style>